var a = require("../../../@babel/runtime/helpers/interopRequireDefault")(require("../../../@babel/runtime/regenerator")),
  t = require("../../../@babel/runtime/helpers/defineProperty"),
  e = require("../../../@babel/runtime/helpers/asyncToGenerator"),
  d = getApp(),
  i = require("../../../mybehaviors/imageSrcP");

Component({
  behaviors: [i],
  properties: {
    datas: {
      type: null
    },
    component_id: {
      type: null
    },
    page_id: {
      type: null
    },
    index: {
      type: null
    },
    U_tabcontrol: {
      type: null
    },
    bottomShowBol: {
      type: null
    },
    bottomShowBolIndex: {
      type: null
    },
    isLast: {
      type: null
    },
    plugin_active: {
      type: null
    },
    store_alone_temp: {
      type: null
    },
    childComponent: {
      type: null,
      value: "goods"
    },
    childStyle: {
      type: null,
      value: ""
    },
    indTab: {
      type: null
    },
    indexTab: {
      type: null
    },
    infoTab: {
      type: null
    },
    second_list_key: {
      type: null
    },
    all: {
      type: null
    },
    totalAll: {
      type: null
    },
    store_id: {
      type: null
    }
  },
  data: {
    integral: "积分",
    showList: !1,
    emptyImage: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/image.png",
    clientWidth: "375",
    list: [],
    language: "",
    alreadyHandleArray: [],
    arrIndex: 1,
    market_price_text: "",
    price_text: "",
    goods_cofig: [],
    per_page: 12,
    page: 1,
    total_page: 0,
    isLoadMore: !0,
    allLoaded: !1,
    tempList: [13157, 1111, 1251],
    isMoneyUnitNiu: false,

    tabs: [  
      { text: '选项卡1' },  
      { text: '选项卡2' },  
      { text: '选项卡3' }  
    ],  
    hunhuoDataTabs: [],
    currentTab: 0 
  },
  lifetimes: {
    attached: function () {
      var a = wx.getStorageSync("langIndex");
      // var isMoneyUnitNiu = wx.getStorageSync('isMoneyUnitNiu')
      // if (isMoneyUnitNiu) {
      //   a.en.money = '牛证'
      // }
      this.setData({
        language: a.en,
        thumb_parameter: this.getyz_basic_info()
      });
      var t = wx.getStorageSync("yz_basic_info").lang.goods,
        e = t && t.price ? t.price : "现价",
        d = t && t.market_price ? t.market_price : "原价",
        i = t && t.vip_price ? t.vip_price : "会员价",
        s = wx.getStorageSync("yz_basic_info").home.mailInfo.scribing_show && 1 == wx.getStorageSync("yz_basic_info").home.mailInfo.scribing_show ? 1 : 0;
      this.setData({
        price_text: e,
        market_price_text: d,
        vip_price_txt: i,
        scribing_show: s
      });
      var r = wx.getStorageSync("integral");
      r && this.setData({
        integral: r
      });
    },
    moved: function () {},
    detached: function () {}
  },
  attached: function () {},
  ready: function () {
    
    // console.log('jjjjjjj',wx.getStorageSync('isMoneyUnitNiu'),this.data.hunhuoDataTabs,this.data.bottomShowBolIndex)
    let isMoneyUnitNiu = wx.getStorageSync('isMoneyUnitNiu')
    if(isMoneyUnitNiu) {
      this.setData({
        isMoneyUnitNiu:isMoneyUnitNiu
      })
      // let _this= this;
      // d._getNetWork({
      //   url: d.getNetAddresss("HuanNiu.get_store_cate"),
      //   data: {},
      //   success: function (res) {
      //     console.log(res.data.data,'get_store_cate')
      //     let arr = [
      //       {
      //         text: '全部',
      //         cate_id: ''
      //       }
      //     ]
      //     let datas = res.data.data
      //     if(res.data.result == 1){
      //       datas.forEach(item=> {
      //         arr.push({
      //           text: item.name,
      //           cate_id: item.id
      //         })
      //       })
      //     }
      //     console.log(arr,'arrrrrrr')
      //     _this.setData({
      //       hunhuoDataTabs: arr
      //     })
      //     console.log(_this.data.hunhuoDataTabs,'hunhuoDataTabs')
      //     _this.getCateGoodsList()
      //   }
      // })
    }
    this.setData({
      clientWidth: wx.getSystemInfoSync().windowWidth
    });
    var a = wx.getStorageSync("yz_basic_info");
    let arr = this.data.datas.list.data
    let arr1;
    let _this = this
    d._getNetWork({
      url: d.getNetAddresss("HuanNiu.zc_goodsis"),
      data: {},
      success: function (a) {
        // console.log(a.data.data, 'HuanNiu.zc_goodsis')
        
        _this.data.tempList = a.data.data

        arr1 = arr.map((items) => {
          let aaa = _this.data.tempList.includes(items.id)
          // let  aaa = this.data.tempList.find(item => item == items.id);
          // console.log(aaa, 'aaaaaaaaaaaa')
          return {
            ...items,
            moneyUnit: _this.data.tempList.includes(items.id) ? '￥' : '牛证'
          }
        })

        // _this.setData({
        //   list: arr1
        // })
      },
      fail: function (a) {
        wx.hideLoading({
          success: function (a) {}
        }), console.log(a);
      }
    });

    // let arr = this.data.datas.list.data
    // arr.forEach((item) => {
    //   console.log(item.point,'pointtttttt')
    //   if (!item.point) {
    //     d._getNetWork({
    //       url: d.getNetAddresss("HuanNiu.goods_text"),
    //       data: {
    //         goods_id: item.id
    //       },
    //       success: function (a) {
    //         console.log(a, 'HuanNiu.goods_text')
    //         // return a.data.data
    //         item.moneyUnit = a.data.data

    //       },
    //       fail: function (a) {
    //         wx.hideLoading({
    //           success: function (a) {}
    //         }), console.log(a);
    //       }
    //     });
    //     console.log(arr, 'arrarrarrarrarrarrarr')
    //   }

    //   // return {
    //   //   ...item,
    //   //   moneyUnit: aaa
    //   // }
    // })
    // console.log(arr, 'this.data.datasthis.data.datas')
    // this.setData({
    //   list: arr.slice(0, this.data.per_page)
    // })
    // console.log(this.data.list, 'jajajajajaja')
    // console.log(wx.getStorageSync('isMoneyUnitNiu'))
    // let isMoneyUnitNiu = wx.getStorageSync('isMoneyUnitNiu')

    a.home.plugin && a.home.plugin.goods_show && this.setData({
      goods_cofig: a.home.plugin.goods_show.goods_group,
      goods_style_set: a.plugin_setting.good_style
    }), "goods" == this.data.childComponent ? this.data.datas.list.data ? (this.setData({
      total_page: this.data.datas.list.last_page,
      page: this.data.datas.list.current_page,
      per_page: this.data.datas.list.per_page,
      alreadyHandleArray: this.data.datas.list.data,
      list: this.data.datas.list.data.slice(0, this.data.per_page),//商品列表
    }), this.data.total_page <= this.data.page && this.setData({
      isLoadMore: !1,
      allLoaded: !0
    }), this.data.datas.get_number && this.data.datas.get_number <= this.data.per_page && this.setData({
      isLoadMore: !1,
      allLoaded: !0,
      list: this.data.datas.list.data.slice(0, this.data.datas.get_number)
    })) : this.setData({
      isLoadMore: !1,
      allLoaded: !0,
      list: this.data.datas.list
    }) : (this.setData({
      total_page: this.data.datas.list.last_page,
      page: this.data.datas.list.current_page,
      per_page: this.data.datas.list.per_page,
      alreadyHandleArray: this.data.datas.list.data,
      list: this.data.datas.list.data
    }), this.data.total_page <= this.data.page && this.setData({
      isLoadMore: !1,
      allLoaded: !0
    })), this.setData({
      showList: !0
    });

    setTimeout(()=>{
      this.setData({
        list: arr1
      })
      console.log(this.data.list, arr1,'listststsst')
    },2000)
   
  },
  pageLifetimes: {
    show: function () {},
    hide: function () {},
    resize: function () {}
  },
  methods: {
    // getCateGoodsList: function(){
    //   d._getNetWork({
    //     url: d.getNetAddresss("HuanNiu.get_store_list"),
    //     data: {
    //       cate_id: this.data.hunhuoDataTabs[0].cate_id,
    //       page: this.page
    //     },
    //     success: function (e) {
    //       console.log(e,'get_store_list')
    //     }
    //   })
    // },
    // onTabSwitch(e) {  
    //   console.log(e,'onTabSwitch')
    //   let tab  = e.target.dataset.tab;  
    //   this.setData({  
    //     currentTab: tab  
    //   });  
    // },

    tabTwoContro: function (a, t) {
      var e = this;
      "tab" == this.data.childComponent && (wx.showLoading({
        title: "加载中",
        icon: "none"
      }), this.data.list = [], this.setData({
        total_page: a.last_page,
        page: a.current_page,
        per_page: a.per_page,
        alreadyHandleArray: a.data,
        list: a.data
      }, function (a) {
        wx.hideLoading({}), e.triggerEvent("onReadEnd", {
          index: t
        });
      }), this.data.total_page <= this.data.page && this.setData({
        isLoadMore: !1,
        allLoaded: !0
      }));
    },
    getKeyInd: function (a, t) {
      var e = this;
      return new Promise(function (t, d) {
        a[e.data.indexTab].forEach(function (a, e) {
          a.tabSelectShow == a.id && t(a);
        });
      });
    },
    getAllKey: function (a, t) {
      return new Promise(function (e, d) {
        t.second_list.forEach(function (t, d) {
          t.id == a.id && e(d);
        });
      });
    },
    getMoreDataTest: function (i) {
      var s = this;
      return e(a.default.mark(function e() {
        var i, r, n, o, l, g, p;
        return a.default.wrap(function (a) {
          for (;;) switch (a.prev = a.next) {
            case 0:
              return i = s.data.indexTab, r = s.data.indTab, n = s.data.infoTab, o = {
                page: s.data.page + 1,
                decorate_id: s.data.page_id,
                component_id: s.data.component_id,
                component_key: "U_moretabcontrol"
              }, s.setData({
                page: s.data.page
              }), a.next = 7, s.getKeyInd(s.data.all, n);

            case 7:
              return l = a.sent, a.next = 10, s.getAllKey(l, s.data.totalAll);

            case 10:
              g = a.sent, o.component_info = {
                  list_key: i,
                  second_list_key: g,
                  components_key: r
                }, o.component_info = JSON.stringify(o.component_info), wx.showLoading({
                  title: "加载中"
                }), s.properties.store_id && (o.store_id = s.properties.store_id), p = d.getNetAddresss("home-page.get-decorate-page"),
                d._getNetWork({
                  url: p,
                  data: o,
                  success: function (a) {
                    console.log('home-page.get-decorate-page1', a)
                    if (1 == a.data.result) {
                      var e, d, i = a.data.data;
                      d = s.data.list.concat(i.data), s.setData((e = {
                          total_page: i.last_page,
                          page: i.current_page
                        }, t(e, "infoTab.remote_data.list.current_page", i.current_page), t(e, "infoTab.remote_data.list.last_page", i.last_page),
                        t(e, "list", d), e));
                    }
                    wx.hideLoading({
                      success: function (a) {}
                    });
                  },
                  fail: function (a) {
                    wx.hideLoading({
                      success: function (a) {}
                    }), console.log(a);
                  }
                });

            case 17:
            case "end":
              return a.stop();
          }
        }, e);
      }))();
    },
    gotoDetail: function (a) {
      var t = a.currentTarget.dataset.item.id,
        e = a.currentTarget.dataset.item.category_option_id ? "&coid=".concat(a.currentTarget.dataset.item.category_option_id) : "";
      69 == a.currentTarget.dataset.item.plugin_id ? wx.navigateTo({
        url: "/packageA/detail_v2/detail_v2?id=" + t + "&name=69" + e
      }) : 78 == a.currentTarget.dataset.item.plugin_id ? wx.navigateTo({
        url: "/packageA/detail_v2/detail_v2?id=" + t + "&md=1" + e
      }) : wx.navigateTo({
        url: "/packageA/detail_v2/detail_v2?id=" + t + e
      });
    },
    openShare: function (a) {
      var t = a.target.dataset.item || a.currentTarget.dataset.item;
      this.triggerEvent("componentGoodShare", t);
    },
    getMoreData: function () {
      var a = this,
        t = this;
      if (this.data.alreadyHandleArray.slice(this.data.per_page * this.data.arrIndex).length >= this.data.per_page) return t.setData({
        list: this.data.list.concat(this.data.alreadyHandleArray.slice(this.data.per_page * this.data.arrIndex, this.data.per_page * (this.data.arrIndex + 1))),
        arrIndex: this.data.arrIndex + 1
      }), void(this.data.datas.get_number && this.data.list.length > this.data.datas.get_number && this.setData({
        isLoadMore: !1,
        allLoaded: !0,
        list: this.data.list.slice(0, this.data.datas.get_number)
      }));
      if (this.setData({
          isLoadMore: !1
        }), t.data.page >= t.data.total_page) this.data.alreadyHandleArray.slice(this.data.per_page * this.data.arrIndex).length > 0 && t.setData({
        list: this.data.list.concat(this.data.alreadyHandleArray.slice(this.data.per_page * this.data.arrIndex, this.data.per_page * (this.data.arrIndex + 1))),
        arrIndex: this.data.arrIndex + 1
      }), this.data.datas.get_number && this.data.list.length > this.data.datas.get_number && this.setData({
        list: this.data.list.slice(0, this.data.datas.get_number)
      });
      else {
        t.setData({
          page: t.data.page + 1
        });
        var e = d.getNetAddresss("home-page.get-decorate-page");
        e += "&page=" + t.data.page, e += "&decorate_id=" + t.data.page_id, e += "&component_id=" + t.data.component_id,
          this.data.U_tabcontrol ? (e += "&component_key=U_tabcontrol", e += "&component_info=" + JSON.stringify({
            list_key: this.data.index
          })) : e += "&component_key=U_goods", this.properties.store_id && (e += "&store_id=".concat(this.properties.store_id)),
          d._getNetWork({
            url: e,
            success: function (e) {
              var d = e.data;
              // console.log('home-page.get-decorate-page2', d.data,t.data.tempList)
              if (1 == d.result) {
                console.log(d,'dddddd',t)
                var i = t.data.list;
                // var dataList = d.data[0].remote_data.list.data
                a.data.U_tabcontrol ? (t.setData({
                  page: d.data[0].remote_data.list.current_page || a.data.page,
                  alreadyHandleArray: a.data.alreadyHandleArray.concat(d.data[0].remote_data.list.data)
                }),
                t.setData({
                  list: i.concat(a.data.alreadyHandleArray.slice(a.data.per_page * a.data.arrIndex, a.data.per_page * (a.data.arrIndex + 1))),
                  arrIndex: a.data.arrIndex + 1
                }), a.data.alreadyHandleArray.slice(a.data.per_page * a.data.arrIndex).length > 0 || t.data.page < t.data.total_page ? t.setData({
                  isLoadMore: !0
                }) : t.setData({
                  allLoaded: !0
                })) : (
                arr = d.data.data,
                arr1 = arr.map((items) => {
                  // let  aaa = this.data.tempList.find(item => item == items.id);
                  // console.log(aaa, 'aaaaaaaaaaaa')
                  return {
                    ...items,
                    moneyUnit: t.data.tempList.includes(items.id) ? '￥' : '牛证'
                  }
                }),
                console.log(arr1,'arr1arr1arr1'),
                t.setData({
                  page: d.data.current_page || a.data.page,
                  alreadyHandleArray: a.data.alreadyHandleArray.concat(arr1),
                  // alreadyHandleArray: a.data.alreadyHandleArray.concat(d.data.data)
                }), t.setData({
                  list: i.concat(a.data.alreadyHandleArray.slice(a.data.per_page * a.data.arrIndex, a.data.per_page * (a.data.arrIndex + 1))),
                  arrIndex: a.data.arrIndex + 1
                }), a.data.alreadyHandleArray.slice(a.data.per_page * a.data.arrIndex).length > 0 || t.data.page < t.data.total_page ? t.setData({
                  isLoadMore: !0
                }) : t.setData({
                  allLoaded: !0
                })), a.data.datas.get_number && a.data.list.length > a.data.datas.get_number && a.setData({
                  isLoadMore: !1,
                  allLoaded: !0,
                  list: a.data.list.slice(0, a.data.datas.get_number)
                });
                console.log(t.data.list,'a.data.alreadyHandleArray')
              } else t.setData({
                page: t.data.page - 1,
                isLoadMore: !1,
                allLoaded: !0
              });
            },
            fail: function (a) {
              console.log(a);
            }
          });
      }
    },
    loadMoreMemberData: function () {
      var a = this,
        t = this;
      if (t.setData({
          isLoadMore: !1
        }), t.data.page >= t.data.total_page) this.data.alreadyHandleArray.slice(12 * this.data.arrIndex).length > 0 && t.setData({
        list: this.data.list.concat(this.data.alreadyHandleArray.slice(12 * this.data.arrIndex, 12 * (this.data.arrIndex + 1))),
        arrIndex: this.data.arrIndex + 1
      });
      else {
        t.setData({
          page: t.data.page + 1
        });
        var e = d.getNetAddresss("member.member.plugin-data");
        1 == this.data.store_alone_temp ? e = d.getNetAddresss("plugin.store-alone-temp.frontend.member.nav-data") : 2 == this.data.store_alone_temp && (e = d.getNetAddresss("plugin.store-alone-temp.frontend.home.nav-data")),
          e += "&page=" + t.data.page, e += "&code=" + t.data.plugin_active, d._getNetWork({
            url: e,
            success: function (e) {
              var d = e.data;
              if (1 == d.result) {
                var i = t.data.list;
                t.setData({
                  page: d.data.data.current_page || a.data.page,
                  alreadyHandleArray: a.data.alreadyHandleArray.concat(d.data.data.data)
                }), t.setData({
                  list: i.concat(a.data.alreadyHandleArray.slice(12 * a.data.arrIndex, 12 * (a.data.arrIndex + 1))),
                  arrIndex: a.data.arrIndex + 1
                }), t.data.page < t.data.total_page ? t.setData({
                  isLoadMore: !0
                }) : t.setData({
                  allLoaded: !0
                }), t.triggerEvent("setLoadMore", {
                  isLoadMore: t.data.isLoadMore
                });
              } else t.setData({
                page: t.data.page - 1,
                isLoadMore: !1,
                allLoaded: !0
              });
            },
            fail: function (a) {
              console.log(a);
            }
          });
      }
    }
  },
  observers: {
    bottomShowBol: function (a) {

      console.log(a), "tab" != this.data.childComponent && (this.data.U_tabcontrol ? a && this.data.isLast && 5 != this.data.datas.sort_style.choose_icon && this.data.isLoadMore ? this.getMoreData() : this.data.page >= this.data.total_page && this.data.alreadyHandleArray.slice(this.data.per_page * this.data.arrIndex).length > 0 && this.setData({
        list: this.data.list.concat(this.data.alreadyHandleArray.slice(this.data.per_page * this.data.arrIndex, this.data.per_page * (this.data.arrIndex + 1))),
        arrIndex: this.data.arrIndex + 1
      }) : a && this.data.bottomShowBolIndex == this.data.index && 5 != this.data.datas.sort_style.choose_icon && this.data.isLoadMore ? this.getMoreData() : this.data.page >= this.data.total_page && this.data.alreadyHandleArray.slice(this.data.per_page * this.data.arrIndex).length > 0 && this.setData({
        list: this.data.list.concat(this.data.alreadyHandleArray.slice(this.data.per_page * this.data.arrIndex, this.data.per_page * (this.data.arrIndex + 1))),
        arrIndex: this.data.arrIndex + 1
      }));

    }
  }
});